/**
 * @ author: 汪孟苹
 */
define(["jquery","bbcare","comm/datatable/datatable","bch/app/commSearch/commSearch",
    "bch/app/patientManager/prematureList.servers"],function($,$bb,$datatable,$commSearch,$servers) {
    var prematureList = {};

    /**
     * 点击添加患者
     */
    var onAddPatient = function(){
        var params = $bb.getPageParams();
        $(".layout-top-left .title").text(params.title);
        var arg = {
            "queueId":params.queueId,
            "schemeId":params.schemeId,
            "busiTypeList":params.busiTypeList,
            "subBusiTypeList":params.subBusiTypeList,
        };
        var domId = $(this).attr("id");
        $bb.open(params,domId,"bch_addPatient_hide",arg);
    }

    /**
     * 请求录入成功后的回调函数
     */
    var ajaxCreatAuthorCallBack = function(data){
        if( data.rows.length > 0 ){
            $commSearch.ui.creatAuthor({
                "id":"createAuthor",
                "list":data.rows,
            });
        }
    }
    /**
     * 查询路径节点任务信息
     */
    var ajaxTaskNameCallBack = function(data){
        if( data.rows.length > 0 ){
            $commSearch.ui.taskName({
                "id":"seqFrom",
                "list":data.rows,
            });
            $commSearch.ui.taskName({
                "id":"seqTo",
                "list":data.rows,
            });
        }
    }

    prematureList.init = function(){
        // 添加患者
        $("#addPatient").unbind("click");
        $("#addPatient").click(onAddPatient);
        // 录入者
        $commSearch.servers.ajaxCreatAuthor(ajaxCreatAuthorCallBack);
        // 访视进度
        var params = $bb.getPageParams();
        if(params.title) $(".layout-top-left .title").html(params.title);
        var params1 = {
            "busiTypeList":params.busiTypeList,
            "subBusiTypeList":params.subBusiTypeList,
            "schemeId":params.schemeId,
        }
        $commSearch.servers.ajaxTaskName(params1,ajaxTaskNameCallBack);
        // datatable
        var id = $(".layout-bottom table").attr("id");
        $datatable.init({
            "id": id,
            "options": $servers.getOptions()
        });
    }

    return prematureList;
});